package org.vshe.improve.spring.prospring3.ch6.annotation;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

public class AnnotationPointcutExample {
	public static void main(String[] args) {
		SampleAnnotationBean bean = new SampleAnnotationBean();
		
		AnnotationMatchingPointcut pontcut = AnnotationMatchingPointcut.forMethodAnnotation(
				WatchMethodInvocation.class);
		MethodInvocationWatcher watcher = new MethodInvocationWatcher();
		
		
		ProxyFactory factory = new ProxyFactory();
		factory.setTarget(bean);
		factory.addAdvisor(new DefaultPointcutAdvisor(pontcut, watcher));
		SampleAnnotationBean proxy = (SampleAnnotationBean) factory.getProxy();
		proxy.bar();
		proxy.foo();
	}

}
